package com.atguigu.boot.admin.actuator.health;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**注意：
 *      类名必须是以HealthIndicator结尾
 * @author : leimingchao
 * @date Date : 2021年11月21日 22:48
 */
@Component
public class MyCustomHealthIndicator extends AbstractHealthIndicator {

    /**
     * 编写真实的检查方法
     * @param builder
     * @throws Exception
     */
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        //mongodb 获取连接进行测试
        Map<String,Object> map = new HashMap<>();
        if (1 == 1) {
            //健康
            // builder.up();
            builder.status(Status.UP);
            map.put("count",1);
            map.put("ms",100);
        } else {
            builder.status(Status.OUT_OF_SERVICE);
            map.put("error","连接超时");
            map.put("ms",3000);
        }
        builder.withDetail("code",100)
                .withDetails(map);
    }
}
